<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        .active {
            background-color: rgb(255, 187, 0);
        }
    </style>
</head>

<body>
    <ul id="list"></ul>
    <div id="box"></div>
</body>
<script>
    var data = [{ title: "小红", info: 66 }, { title: "小兰", info: 18 }, { title: "小紫", info: 12 }]
    class Tab {
        constructor() {
            this.list = document.querySelector("#list");
            this.box =  document.querySelector("#box");
            this.data = data;
            this.init();

        }
        init() {
            this.render();
            this.bindEvent();
        }
        render() {
            this.list.innerHTML = this.data.map((item, index) => {
                return `
                <li class="${index == 0 ? "active" : ""}">${item.title}</li>
                `
            }).join("")
            this.box.innerHTML = this.data[0].info;
        }
        bindEvent() {
            let lis = [...document.querySelectorAll("li")];
            lis.forEach((item, index) => {
                item.onclick = (e) => {
                    this.box.innerHTML = this.data[index].info;
                    this.list.querySelector(".active").classList.remove("active")
                   e.target.classList.add("active");
                }
            })

        }

    }
    new Tab()
</script>

</html>